package com.xiaojiu.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.xiaojiu.app.App;


/**
 * Created by Jacky on 2016/10/31.
 */
public class AppConfig {

    private static AppConfig appConfig;

    private SharedPreferences preferences;


    /**
     * 屏幕宽
     */
    public static final String ScreenWidth = "screen_width";
    /**
     * 屏幕高
     */
    public static final String ScreenHight = "screen_hight";


    private AppConfig() {
        preferences = App.getInstance().getSharedPreferences("JACKY", Context.MODE_PRIVATE);
    }

    public static AppConfig getInstance() {

        if (appConfig == null)
            synchronized (AppConfig.class) {
                appConfig = new AppConfig();
            }
        return appConfig;
    }

    public void putInt(String key, int value) {
        preferences.edit().putInt(key, value).commit();
    }

    public int getInt(String key, int defValue) {
        return preferences.getInt(key, defValue);
    }

    public int getInt(String key) {
        return getInt(key, 0);
    }

    public void putString(String key, String value) {
        preferences.edit().putString(key, value).commit();
    }

    public String getString(String key, String defValue) {
        return preferences.getString(key, defValue);
    }

    public String getString(String key) {
        return preferences.getString(key, "");
    }

    public void putBoolean(String key, boolean value) {
        preferences.edit().putBoolean(key, value).commit();
    }

    public boolean getBoolean(String key, boolean defValue) {
        return preferences.getBoolean(key, defValue);
    }

    public boolean getBoolean(String key) {
        return preferences.getBoolean(key, false);
    }

    public void putLong(String key, long value) {
        preferences.edit().putLong(key, value).commit();
    }

    public long getLong(String key, long defValue) {
        return preferences.getLong(key, defValue);
    }

    public long getLong(String key) {
        return preferences.getLong(key, 0);
    }

    public void putFloat(String key, float value) {
        preferences.edit().putFloat(key, value).commit();
    }

    public float getFloat(String key, float defValue) {
        return preferences.getFloat(key, defValue);
    }

    public float getFloat(String key) {
        return preferences.getFloat(key, 0);
    }

}
